package com.teen9g.infoplatformserver.controller;

import com.teen9g.entity.SingleRecentEdit;
import com.teen9g.infoplatformserver.service.RecentEditService;
import com.teen9g.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 最近编辑控制类
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/recentEdit")
public class RecentEditController {

    @Autowired
    private RecentEditService recentEditService;

    @GetMapping
    public Result<List<SingleRecentEdit>> getRecentEdit() {
        log.info("获取最近15条编辑记录");
        List<SingleRecentEdit> list = recentEditService.getRecentEdit();
        return Result.success(list);
    }

    /**
     * 获取最近15条被编辑的文章
     */
    @GetMapping("/canteenShop")
    public Result<List<SingleRecentEdit>> CS_getRecentEdit() {
        log.info("获取最近15条被编辑的食堂店铺相关的文章");
        List<SingleRecentEdit> list = recentEditService.CS_getRecentEdit();
        return Result.success(list);
    }

    /**
     * 获取食堂店铺相关且id为{id}的所有编辑记录
     */
    @GetMapping("/canteenShop/{id}")
    public Result<List<SingleRecentEdit>> CS_getRecentEditById(@PathVariable Integer id) {
        log.info("获取食堂店铺相关且id为{}的所有编辑记录", id);
        List<SingleRecentEdit> list = recentEditService.CS_getRecentEditById(id);
        return Result.success(list);
    }

    /**
     * 获取最近15条被编辑的教学楼相关的编辑记录
     */
    @GetMapping("/teachingBuilding")
    public Result<List<SingleRecentEdit>> TB_getRecentEdit() {
        log.info("获取最近15条被编辑的教学楼相关的编辑记录");
        List<SingleRecentEdit> list = recentEditService.TB_getRecentEdit();
        return Result.success(list);
    }

    /**
     * 获取教学楼相关且id为{id}的所有编辑记录
     */
    @GetMapping("/teachingBuilding/{id}")
    public Result<List<SingleRecentEdit>> TB_getRecentEditById(@PathVariable Integer id) {
        log.info("获取教学楼相关且id为{}的所有编辑记录", id);
        List<SingleRecentEdit> list = recentEditService.TB_getRecentEditById(id);
        return Result.success(list);
    }

    /**
     * 获取舞萌中二相关且id为{id}的所有编辑记录
     */
    @GetMapping("/maimaiChunithm/{id}")
    public Result<List<SingleRecentEdit>> MC_getRecentEditById(@PathVariable Integer id) {
        log.info("获取舞萌中二相关且id为{}的所有编辑记录", id);
        List<SingleRecentEdit> list = recentEditService.MC_getRecentEditById(id);
        return Result.success(list);
    }

    /**
     * 获取运动场相关且id为{id}的所有编辑记录
     */
    @GetMapping("/playground/{id}")
    public Result<List<SingleRecentEdit>> PG_getRecentEditById(@PathVariable Integer id) {
        log.info("获取运动场相关且id为{}的所有编辑记录", id);
        List<SingleRecentEdit> list = recentEditService.PG_getRecentEditById(id);
        return Result.success(list);
    }
}
